package com.ruoyi.web.controller.apply.api;

import com.ruoyi.activity.service.IApplyService;
import com.ruoyi.common.annotation.Check;
import com.ruoyi.common.annotation.RequestLock;
import com.ruoyi.common.annotation.SystemLog;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.model.apply.dto.ApplyInfoDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * @author : 张怀秋
 * 报名控制层
 **/
@Api(tags = "报名服务")
@Slf4j
@RestController
@RequestMapping("/api/apply")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ApplyController extends BaseController {

    /**
     * 报名服务
     */
    private final IApplyService applyService;


    @ApiOperation(value = "点击立即报名 活动、竞赛等接口", notes = "1.需要传递当前所在的竞赛或者活动id给该接口" +
            "2.需要传递类型字段给该接口 0-> 竞赛 1-> 活动" +
            "3.需要注意的是这个是点击立即报名按钮才会触发的接口而不是确认报名 返回的是报名模板")
    @Check
    @SystemLog(businessName = "展示对应详情报名模板")
    @GetMapping("/user-template-application/{detailId}/{type}")
    public AjaxResult templateApplication(@ApiParam("详情id") @PathVariable String detailId, @ApiParam("类型") @PathVariable String type) {
        return applyService.queryDetailApplicationTemplate(detailId, type);
    }

    @ApiOperation("点击确认报名,保存报名、竞赛触发的接口")
    @Check
    @SystemLog(businessName = "保存、报名接口")
    @PostMapping("/user-submit-application")
    @RequestLock(prefix = "submitApplication", expire = 1, timeUnit = TimeUnit.SECONDS)
    public AjaxResult submitApplication(@ApiParam("提交的报名信息 " +
            "其中需要包含一个type字段区分要决定的报名状态")
                                        @RequestBody ApplyInfoDto applyInfoDto) {
        return applyService.submitApply(applyInfoDto);
    }
}
